﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>ASP.NET Boilerplate - Module Zero</title>
<link type="text/css" rel="stylesheet" href="../bootstrap.min.css" />
</head>

<body>

<div class="document-contents">

<h3>Role Entity</h3>
<p>Role entity represents a <strong>role for the application</strong>. It should be derived from 
<strong>AbpRole</strong> class as shown below:</p>
<pre lang="cs">public class Role : AbpRole&lt;Tenant, User&gt;
{
    //add your own role properties here
}</pre>
<p>This class is created when you <a href="/Pages/Documents/Zero/Installation">install</a> module-zero. 
Roles are stored in <strong>AbpRoles</strong> table in the database. You can add 
your custom properties to Role class (and create database migrations for the 
changes).</p>
<p>AbpRole defines some properties. Most importants are:</p>
	<ul>
		<li><strong>Name</strong>: Unique name of the role in the tenant.</li>
		<li><strong>DisplayName</strong>: Shown name of the role.</li>
		<li><strong>IsDefault</strong>: Is this role assigned to new users by 
		default?</li>
		<li><strong>IsStatic</strong>: Is this role static (pre-build and can 
		not be deleted).</li>
	</ul>
<p>Roles are used to <strong>group permissions</strong>. When a user has a role, 
then he/she will have all permissions of that role. A user can have <strong>
multiple</strong> roles. Permissions of this user will be a merge of all 
permissions of all assigned roles.</p>
	<h4>Dynamic vs Static Roles</h4>
	<p>In module-zero, roles can be 
dynamic or static:</p>
<ul>
	<li><strong>Static role</strong>: A static role has a known <strong>name
	</strong>(like 'admin') and can not change this name (we can change <strong>
	display name</strong>). It's exists on the system startup and can not be 
	deleted. Thus, we can write codes based on a static role name.</li>
	<li><strong>Dynamic (non static) role</strong>: We can create a dynamic role 
	after deployment. Then we can grant permissions for that role, we can assign 
	the role to some users and we can delete it. We can not know names of 
	dynamic roles in development time.</li>
</ul>

	<p>Use <strong>IsStatic</strong> property to set it for a role. Also, we should 
	<strong>register </strong>static 
	roles on <a href="/Pages/Documents/Module-System">
	PreInitialize</a> of our module. Assume that we have an "Admin" static role 
	for tenants:</p>
	<pre lang="cs">Configuration.Modules.Zero().RoleManagement.StaticRoles.Add(new StaticRoleDefinition(&quot;Admin&quot;, MultiTenancySides.Tenant));</pre>
	<p>Thus, module-zero will be aware of static roles.</p>

	<h4>Default Roles</h4>
	<p>One or more roles can be set as <strong>default</strong>. Default roles are 
assigned to new added/registered users as default. This is not a development 
time property and can be set or changed after deployment. Use <strong>IsDefault</strong> 
	property to set it.</p>
	<h3>Role Manager</h3>
<p><strong>RoleManager </strong>is a service to perform <strong>domain logic</strong> 
for roles:</p>
<pre lang="cs">public class RoleManager : AbpRoleManager&lt;Tenant, Role, User&gt;
{
    //...
}</pre>
<p>You can <a href="/Pages/Documents/Dependency-Injection">inject</a> and use 
RoleManager to create, delete, update roles, grant permissions for 
roles and much more. You can add your own methods here. Also, you can
<strong>override</strong> any method of <strong>AbpRoleManager</strong> base class for your own needs.</p>
	<p>Like UserManager, Some methods of RoleManager also return IdentityResult 
	as a result instead of throwing exceptions for some cases. See
	<a href="/Pages/Documents/Zero/User-Management">user management</a> document 
	for more information.</p>
	<h3>Multi Tenancy</h3>
	<p>Similar to user management, role management also works for single tenant 
	in one time in a multi-tenant application. See
	<a href="/Pages/Documents/Zero/User-Management#multi-tenancy">user 
	management</a> document for more information.</p>

</div>

</body>

</html>
